<?php
class LoginAction extends Action {
	
	public function login()
	{
		$this->display();
	}
	
	// 登录检测
	public function checkLogin() {
		$username = $this->_post('username');
		$password = $this->_post('password');
		$errorInfo = array();
		
		if(empty($username) || $username != "admin"){
			$errorInfo["status"] = "300";
			$errorInfo["message"] = "帐号错误！";
			echo json_encode($errorInfo);
		}else if(empty($password) || $password != "admin"){
			$errorInfo["status"] = "300";
			$errorInfo["message"] = "密码错误！";
			echo json_encode($errorInfo);
		}else{
			session("username",$username);
        	$errorInfo["status"] = "200";
			$errorInfo["message"] = "登录成功！";
			echo json_encode($errorInfo);
		}
	}
	
	// 用户登出
    public function logout()
    {
        if(isset($_SESSION["username"])) {
			session(null); 
			session_destroy();
            $this->assign("jumpUrl",__URL__.'/login/');
            $this->success('登出成功！');
        }else {
            $this->error('已经登出！');
        }
    }		
}